package com.yunmai.cloud.web.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunmai.cloud.web.domain.CommandInfoEntity;
import com.yunmai.cloud.web.repositories.ICommandInfoRepository;
import com.yunmai.cloud.web.repositories.orm.ICommandInfoMapper;
import com.yunmai.cloud.web.services.ICommandInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 *
 *  相关文章：https://zhuanlan.zhihu.com/p/616226055
 * </p>
 *
 * @author 赵刚
 * @since 2023-01-11
 **/
@Service
public class CommandInfoServiceImpl implements ICommandInfoService {

    @Autowired
    ICommandInfoMapper commandInfoMapper;
    @Autowired
    private ICommandInfoRepository commandInfoRepository;

    @Override
    public void create(CommandInfoEntity commandInfoEntity) {
        commandInfoMapper.insert(commandInfoEntity);
    }

    @Override
    public void update(CommandInfoEntity commandInfoEntity) {
        commandInfoMapper.updateById(commandInfoEntity);
    }

    @Override
    public CommandInfoEntity getByIdAndFinished(String id,Boolean isFinished) {
        LambdaQueryWrapper<CommandInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper = queryWrapper.eq(CommandInfoEntity::getId,id).
                eq(CommandInfoEntity::getIsFinished,isFinished);
        return commandInfoMapper.selectOne(queryWrapper);
    }
}
